package com.jyw.business.ast.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;

import com.jyw.business.ast.domain.dto.web.AstAllocateDto;
import com.jyw.business.ast.domain.dto.web.AstAllocatePageDto;
import com.jyw.business.ast.domain.vo.web.AllocateDetailVo;
import com.jyw.business.ast.domain.vo.web.AllocatePageVo;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.BasePage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.enums.BusinessType;
import com.jyw.business.ast.service.IAstAllocateService;
import com.jyw.common.core.page.TableDataInfo;

/**
 * 资产-调拨信息Controller
 * 
 * @author system
 * @date 2023-10-19
 */
@RestController
@RequestMapping("/ast/allocate")
@Api(tags = "资产调拨")
public class AstAllocateController extends BaseController
{
    @Resource
    private IAstAllocateService astAllocateService;

    /**
     * 查询资产-调拨信息列表
     */
    @PreAuthorize("@ss.hasPermi('ast:allocate:list')")
    @PostMapping("/list")
    @ApiOperation("资产调拨分页查询")
    public TableDataInfo<AllocatePageVo> list(BasePage page, @RequestBody @Valid AstAllocatePageDto astAllocate)
    {
        startPage();
        List<AllocatePageVo> list = astAllocateService.allocatePage(astAllocate);
        return getDataTable(list);
    }


    /**
     * 获取资产-调拨信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ast:allocate:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("调拨详情")
    public CommonResult<AllocateDetailVo> getInfo(@PathVariable("id") Long id)
    {
        return CommonResult.success(astAllocateService.selectDetail(id));
    }

    /**
     * 新增资产-调拨信息
     */
    @PreAuthorize("@ss.hasPermi('ast:allocate:add')")
    @Log(title = "资产-调拨信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("资产调拨")
    public CommonResult add(@RequestBody @Valid AstAllocateDto dto)
    {
        astAllocateService.allocate(dto);
        return CommonResult.success();
    }

    /**
     * 删除资产-调拨信息
     */
    @PreAuthorize("@ss.hasPermi('ast:allocate:remove')")
    @Log(title = "资产-调拨撤销", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    @ApiOperation("撤销")
    public CommonResult remove(@PathVariable Long id)
    {
        astAllocateService.revoke(id);
        return CommonResult.success();
    }
}
